package cn.web.web_module.controller;

import cn.itcast.mapper.orderMapper;
import cn.itcast.pojo.order;
import cn.itcast.pojo.orderItem;
import cn.itcast.pojo.packageOrderItem;
import cn.itcast.pojo.recharge;
import cn.itcast.util.DateUtils;
import cn.itcast.util.OutputStringController;
import cn.itcast.util.ResponseEntity;
import cn.web.web_module.entity.*;
import cn.web.web_module.service.BusinessDataService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 张松
 * @Description:
 * @Date: Created in 15:16 2020/8/17
 * @Modified By:
 */
@RestController
@RequestMapping("/Business")
@Slf4j
public class BusinessDataController {

    @Resource
    private BusinessDataService businessDataService;

    @Resource
    OutputStringController osc;

    @RequestMapping("hello")
    public String testLog(){
        log.info("hello-测试成功了吗?我不信 红红火火恍恍惚惚");
        return "hello";
    }


    /**
     *
     * @Description: 每个月用户量
     *
     * @auther: 张松
     * @date: 15:20 2020/8/17
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("EveryMonthAddUser")
    public ResponseEntity EveryMonthAddUser(){
        List<MonthData> monthData = businessDataService.EveryMonthAddUser();
        try {
            if (!monthData.isEmpty()||monthData.size()>0)return new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 全部用户数
     *
     * @auther: 张松
     * @date: 15:20 2020/8/17
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("AllUserData")
    public ResponseEntity AllUserData(){
        List<MonthData> monthData = businessDataService.AllUserData();
        try {
            if (!monthData.isEmpty()||monthData.size()>0)return  new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 每月订单量
     *
     * @auther: 张松
     * @date: 15:22 2020/8/17
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("EveryMonthAddOrder")
    public ResponseEntity EveryMonthAddOrder(){
        List<MonthData> monthData = businessDataService.EveryMonthAddOrder();
        try {
            if (!monthData.isEmpty()||monthData.size()>0)return  new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 累计订单量
     * 
     * @auther: 张松
     * @date: 15:26 2020/8/17
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("AllOrderData")
    public ResponseEntity AllOrderData(){
        List<MonthData> monthData = businessDataService.AllOrderData();
        try {
            if (!monthData.isEmpty()||monthData.size()>0)return  new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 每个月收多少重量
     *
     * @auther: 张松
     * @date: 12:36 2020/8/18
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("EveryMonthWeight")
    public ResponseEntity EveryMonthWeight(){
        List<MonthData> monthData = businessDataService.EveryMonthWeight();
        try{
            if (!monthData.isEmpty()||monthData.size()>0){
                return new ResponseEntity(monthData);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }


    /**
     *
     * @Description:  累计多少货
     *
     * @auther: 欧阳辉
     * @date: 12:42 2020/8/18
     * @param:
     * @return:
     *
     */
    @RequestMapping("AllWeight")
    public ResponseEntity AllWeight(){
        List<MonthData> monthData = businessDataService.AllWeight();
        try{
            if (!monthData.isEmpty()||monthData.size()>0) return new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description:  每个月各个品类多少货
     *
     * @auther: 张松
     * @date: 12:42 2020/8/18
     * @param:
     * @return:
     *
     */
    @RequestMapping("EvenMothProduct")
    public ResponseEntity EvenMothProduct(){
        List<MonthData> monthData = businessDataService.EvenMothProduct();
        try{
            if (!monthData.isEmpty()||monthData.size()>0) return  new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 每个月平均多少货
     *
     * @auther: 张松
     * @date: 12:43 2020/8/18
     * @param: []
     * @return: java.util.List<cn.web.web_module.entity.MonthData>
     *
     */
    @RequestMapping("AverageWeight")
    public ResponseEntity AverageWeight(){
        List<MonthData> monthData = businessDataService.AverageWeight();
        try{
            if (!monthData.isEmpty()||monthData.size()>0) return  new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }


    /**
     *
     * @Description: 每个月用户收入多少钱
     *
     * @auther: 张松
     * @date: 12:43 2020/8/18
     * @param: []
     * @return: java.util.List<cn.web.web_module.entity.MonthData>
     *
     */
    @RequestMapping("UserEarning")
    public ResponseEntity UserEarning(){
        List<MonthData> monthData = businessDataService.UserEarning();
        try{
            if (!monthData.isEmpty()||monthData.size()>0) return new ResponseEntity(monthData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 每个月多少单,平均每单多少重量
     *
     * @auther: 张松
     * @date: 12:42 2020/8/20
     * @param: []
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     *
     */
    @RequestMapping("EvenMonthAvgWeight")
    public ResponseEntity EvenMonthAvgWeight(){
        List<MonthData> monthData = businessDataService.EvenMonthAvgWeight();
        try {
            if (monthData.isEmpty()||monthData.size()>0){
                return new ResponseEntity(monthData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description: 骑手每日收益
     *
     * @auther: 张松
     * @date: 8:20 2020/8/25
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("horesemanEvenDayEarnings")
    public ResponseEntity horesemanEvenDayEarnings(){
        List<order> orders = businessDataService.horesemanEvenDayEarnings();
        try{
            if (!orders.isEmpty()||orders.size()>0){
                return new ResponseEntity(orders);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();

    }


    /**
     *
     * @Description: 查看用户上三次成交价格
     *
     * @auther: 张松
     * @date: 8:59 2020/9/3
     * @param: [openid]
     * @return: java.util.List<cn.itcast.pojo.orderItem>
     *
     */

    @PostMapping("selectPrice")
    public ResponseEntity selectPrice(@RequestBody Map <String,String> openId){
        List<orderItem> orderItemList = businessDataService.selectPrice(openId.get("openId"));
        try {
            if (!orderItemList.isEmpty()||orderItemList.size()>0){
                return new ResponseEntity(orderItemList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResponseEntity("无下单信息").error_300();
    }


    /**
     *
     * @Description: 查找骑手数据
     *
     * @auther: 张松
     * @date: 18:05 2020/9/7
     * @param: [timeDate]
     * @return: cn.itcast.util.ResponseEntity
     *
     */

    @RequestMapping("selectHorsemanData")
    public ResponseEntity selectHorsemanData(Date timeDate){
        Map<String, Object> map = businessDataService.selectHorsemanData(timeDate);
        if (!map.isEmpty()||map.size()>0){
            return new ResponseEntity(map);
        }
        return new ResponseEntity().error_300();
    }



    @PostMapping("selectHorsemanTodayAmount")
    public ResponseEntity selectHorsemanTodayAmount(@RequestBody Map<String,String> map){
        String openId = map.get("openId");
        Integer amount = businessDataService.selectHorsemanTodayAmount(openId);
        ResponseEntity<Integer> integerResponseEntity = new ResponseEntity<>(amount);
        return integerResponseEntity;
    }

    @PostMapping("selectHorsemanYesterdayAmount")
    public ResponseEntity selectHorsemanYesterdayAmount(@RequestBody Map<String,String> map){
        String openId = map.get("openId");
        Integer amount = businessDataService.selectHorsemanYesterdayAmount(openId);
        ResponseEntity<Integer> integerResponseEntity = new ResponseEntity<>(amount);
        return integerResponseEntity;
    }



    /**
     *
     * @Description:
     *
     * @auther: 骑手每个订单的收货记录,出售记录,提现记录,充值记录
     * @date: 11:12 2021/3/9
     * @param: [map]
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("selectHorsemandetailedRecord")
    public ResponseEntity selectHorsemanDetail(Integer page,@RequestParam (required = false,defaultValue = "10")String pageSize, String horsemanName, String[] searchDate){
        Map<String,String> map = new HashMap<>();
        map.put("page",String.valueOf(page));
        map.put("pageSize",pageSize);
        map.put("horsemanName",horsemanName);
        if (searchDate.length>0){
            map.put("beginTime",searchDate[0]);
            map.put("endTime",searchDate[1]);
        }
        PageInfo pageInfo = businessDataService.selectHorsemanDetailedRecord(map);
        return new ResponseEntity(pageInfo);
    }

    /**
     *
     * @Description: 查看全部在职骑手的姓名
     *
     * @auther: 张松
     * @date: 16:18 2021/3/10
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("selectIncumbencyAllHorsemanName")
    public ResponseEntity selectIncumbencyAllHorsemanName(){
        List<String> horsemanName=businessDataService.selectIncumbencyAllHorsemanName();
        return new ResponseEntity(horsemanName);
    }


    /**
     *
     * @Description: 查找骑手订单ID
     *
     * @auther: 张松
     * @date: 14:52 2021/3/11
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("selectHorsemanOrderId")
    public ResponseEntity selectHorsemanOrderId(Integer orderId){

        List<OrderInfoOV> orderInfoOVS = businessDataService.selectHorsemanOrderId(orderId);

        return new ResponseEntity(orderInfoOVS);
    }


    /**
     *
     * @Description: 查找骑手的充值信息
     *
     * @auther: 张松
     * @date: 19:01 2021/3/11
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("selectHorsemanRechargeInfo")
    public ResponseEntity selectHorsemanRechargeInfo(String rechargeNumber){
        List<RechargeInfoOV> rechargeInfoOVS = businessDataService.selectHorsemanRechargeInfo(rechargeNumber);
        return new ResponseEntity(rechargeInfoOVS);
    }


    @RequestMapping("SelectHorsemanWithdrawInfo")
    public ResponseEntity SelectHorsemanWithdrawInfo(Integer withdrawId){
        List<WithdrawInfoOV> withdrawInfoOVS=businessDataService.selectHorsemanWithdrawInfo(withdrawId);
        return new ResponseEntity(withdrawInfoOVS);
    }

    @RequestMapping("selectHorsemanPackageOrderId")
    public ResponseEntity selectHorsemanPackageOrderId(Integer PackageOrderId){
        List<PackageOrderInfoOV> packageOrderInfoOVS=businessDataService.selectHorsemanPackageOrderId(PackageOrderId);
        return new ResponseEntity(packageOrderInfoOVS);
    }


    @RequestMapping("downloadHorsemandetailedRecordExcel")
    public ResponseEntity downloadHorsemandetailedRecordExcel(String horsemanName, String[] searchDate){
        Map<String,String> map = new HashMap<>();
        map.put("horsemanName",horsemanName);
        if (searchDate.length>0){
            map.put("beginTime",searchDate[0]);
            map.put("endTime",searchDate[1]);
        }
        map.put("page",0+"");
        map.put("pageSize",0+"");
        List<HorsemanDetailedRecord> horsemanDetailedRecords = businessDataService.downloadHorsemandetailedRecordExcel(map);
        if(horsemanDetailedRecords.size()!=0){
            return new ResponseEntity(horsemanDetailedRecords);
        }
        return new ResponseEntity(horsemanDetailedRecords);
    }

    /**
     *
     * @Description: 骑手昨天的出货记录
     *
     * @auther: 张松
     * @date: 15:21 2021/4/14
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */

    @RequestMapping("horsemanEvenDayPackageOrder")
    public ResponseEntity horsemanEvenDayPackageOrder(){
        List<packageOrderItem> horsemanEvenDayPackageOrderList=businessDataService.horsemanEvenDayPackageOrder();
        return new ResponseEntity(horsemanEvenDayPackageOrderList);
    }



    @RequestMapping("horsemanContrast")
    public ResponseEntity horsemanContrast(){
        List<HorsemanContrast> horsemanContrast=businessDataService.horsemanContrast();
        return new ResponseEntity(horsemanContrast);
    }


}
